package win.ganbo.easyframwork.commons.utils;

import org.apache.shiro.crypto.hash.SimpleHash;

import java.util.UUID;

/**
 * @author ganbo
 * @create 2017-05-23 22:42
 */
public class ShiroUtil {

    //shiro散列次数
    public static final int hashIterations = 1;


    /**
     * shiro 密码md5加密算法
     * @param source 原密码
     * @param salt  盐
     * @param hashIterations 散列次数
     * @return
     */
    public static String getPasswordByShiroMd5(String source,String salt,int hashIterations){
        SimpleHash simpleHash = new SimpleHash("md5",source,salt,hashIterations);
        return simpleHash.toString();
    }


    /**
     * 随机生成4位字符串用来做shiro加密盐
     * @return
     */
    public static String getSalt(){
        String uuid = UUID.randomUUID().toString().replace("-","");
        return  uuid.substring(uuid.length()-4);
    }


}
